﻿using MediatR;
using SmartMedicalCare.API.Write.Applications.Commands;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers
{
    public class AddHospitalCommandHandler : IRequestHandler<AddHospitalCommand, APIResult<int>>
    {
        private readonly IBaseRespository<HospitalModel> hospRep;

        public AddHospitalCommandHandler(IBaseRespository<HospitalModel> hospRep)
        {
            this.hospRep = hospRep;
        }

        public async Task<APIResult<int>> Handle(AddHospitalCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            result.code=ResultCode.添加成功;
            result.Message=ResultCode.添加成功.ToString();

            HospitalModel hosp=new HospitalModel();
            hosp.Name=request.Name;
            hosp.HospitalImg=request.HospitalImg;
            hosp.IsHospital=request.IsHospital;
            hosp.HospitalCount = request.HospitalCount;
            hosp.HospitalCountTow=request.HospitalCountTow;
            hosp.HospitalAdd=request.HospitalAdd;
            hosp.HospitalAddTow=request.HospitalAddTow;
            hosp.HospitalPhone=request.HospitalPhone;

            hosp.Departments = request.Departments;


            hosp.Intro=request.Intro;
            hosp.CreateName=request.CreateName;
            hosp.CreateTime=DateTime.Now;
            hosp.head = request.head;
            hosp.IsDeleted = false; 
            await hospRep.AddAsync(hosp);

            return await Task.FromResult(result);
        }
    }
}
